package mysql

import (
	"gorm.io/gorm"
	"learning-pass/common/proto/user"
)

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(100);" json:"username"`
	Password string `gorm:"type:varchar(100);" json:"password"`
}

func (u *User) FindUserByUsername(username string) (*User, error) {
	err := DB.Where("username=?", username).Find(&u).Error
	if err != nil {
		return nil, err
	}
	return u, nil
}
func (u *User) CreateUser(in *user.RegisterReq) (*User, error) {
	users := &User{
		Username: in.Username,
		Password: in.Password,
	}
	err := DB.Model(&u).Create(&users).Error
	if err != nil {
		return nil, err
	}
	return u, nil
}
